<?php

namespace App\Admin\Controllers;

use App\Frees;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class FreesController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '免费领取';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Frees());

        $grid->column('id', __('Id'));
        $grid->column('title', "标题");
        $grid->column('imgurl', "图片")->image(config('app.url').'/uploads', 60,60);
        $grid->column('linkurl', "链接地址")->link();
        $grid->column('created_at', __('Created at'));
        $grid->column('updated_at', __('Updated at'));

        $grid->actions(function ($actions) {

            // 去掉查看
            $actions->disableView();
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Frees::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('title', "标题");
        $show->field('imgurl', "图片");
        $show->field('linkurl', "链接地址");
        $show->field('appid', "小程序APPID");
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Frees());

        $form->text('title', "标题");
        $form->text('appid', "小程序APPID");
        $form->image('imgurl', '图片');
        $form->text('linkurl', "跳转链接");

        return $form;
    }
}
